import java.util.ArrayList;
/**
 * This class represents a learning examples of digit.
 * 
 * @author Idan
 *
 */

public class Example implements Comparable<Example>{
	
	
	
	public byte [] byteArray;
	public int digit ;
	
	/**
	 * c'tor
	 * 
	 * @param byteArray the byte array represents the example
	 */
	public Example(byte [] byteArray) {
		this.byteArray = byteArray;
	}
	/**
	 * 
	 * c'tor 
	 * 
	 * 
	 * @param array array of bytes
	 * @param digit the real "answer" . the digit that is repsersnted by the 
	 * example
	 */
	public Example(ArrayList<Byte> array, int digit) {
		byteArray = new byte[array.size()];
		for (int i = 0; i < array.size(); i++) {
			byteArray[i]= array.get(i);
		}
		this.digit=digit;
	}
	public Example() {
		
	}
	@Override
	public String toString() {
	
		StringBuilder builder = new StringBuilder();
		builder.append("[");
		for (int i = 0; i < byteArray.length; i++) {
			if (i%Constants.EXAMPLE_MATIRX_SIZE == 0)
				builder.append("\r\n");
			builder.append(byteArray[i]+",");
		}
		builder.append("]");
		return builder.toString();
		//return Integer.toString(digit);
	}
	@Override
	public int compareTo(Example o) {
		int mistakes=0;
		for (int i = 0; i < byteArray.length; i++) {
			if (byteArray[i]!=o.byteArray[i]){
				mistakes++;
				if (mistakes>=Constants.EXAMPLES_EQUALITY_TRAHSTHOLD)
					return -1;
			}
				
		}
		return 0;
	}
	
}
